import javax.xml.bind.annotation.XmlRootElement;

import codeg.CodeGeneration;
import codeg.CodeGenerationContext;
import codeg.Codeg;
import codeg.CodegException;


@XmlRootElement
public class ColorCodeg extends Codeg {
    static class Color {
        public int red;
        public int green;
        public int blue;

        public Color() {}

        public Color(int r, int g, int b) {
            red = r;
            green = g;
            blue = b;
        }
    }

    private Color color = new Color(0, 0, 0);

    public void setColor(Color color) {
        this.color = color;
    }

    public Color getColor() {
        return color;
    }

    @Override
    public CodeGeneration getCode(CodeGenerationContext context) throws CodegException {
        CodeGeneration code = new CodeGeneration(this);

        /* This codeg only generates Java code currently */
        if (context.getLanguage() != CodeGenerationContext.LANGUAGE.JAVA)
            return code;
        
        code.setGlobalCode("class Color {\n" + 
                     "    public int red;\n" + 
                     "    public int green;\n" + 
                     "    public int blue;\n" + 
                     "    \n" + 
                     "    public Color() {}\n" + 
                     "    \n" + 
                     "    public Color(int r, int g, int b) {\n" + 
                     "        red = r;\n" + 
                     "        green = g;\n" + 
                     "        blue = b;\n" + 
                     "    }\n" + 
                     "}\n");

        Color c = getColor();
        code.setLocalCode("Color " + getId() + " = new Color(" + c.red + ", " + c.green + ", " + c.blue + ")");
        
        return code;
    }
}